<template>
  <el-form-item label="车型" clearable>
    <el-select v-model="value" @change="sendCode" placeholder="请选择" :disabled="disabled">
      <el-option
        v-for="item in options"
        :key="item.compCartypeCode"
        :label="item.compCartypeCn"
        :value="item.compCartypeCode"
      ></el-option>
    </el-select>
  </el-form-item>
</template>

<script>
import { crmApis } from "@/api/apiList/crm";
import { requestAPI } from "@/api/commonRequest";
export default {
  name: "AssignWay",
  props: {
    code: {type:String,default:""},
    pcode:{type:String,default:""},
    disabled:{type:Boolean,default:false},
  },
  data() {
    return {
      value:this.code,
      options: this.getData()
    };
  },
  mounted: function() {
    var parent = this.$utils.getHasFormFieldParentComponent(this);
    if (parent.states == "add") {
      this.value = "";
    }
    //this.getData();
    // this.value=""
  },
  methods: {
    getData: function() {
      let that = this;
      let parent = this.$utils.getHasFormFieldParentComponent(this);
      this.pcode=parent.typeC
      let queryObj = {
        // api配置
        apiConfig: crmApis.mdmCompCarTypeQueryFindAll,
        // 需要调用的API服务配置
        apiServices: [
          {
            //表格中台返回网格的字段
            apiQueryRow: [
                "compCartypeCn",
                "compCartypeCode"
            ]
          }
        ],
        //条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          pageSize: 100,
          pageIndex: 1,
          //当前中台使用的名称有dataInfo、info，具体查看API文档
          dataInfo: {compCarseriesId:this.pcode} //值列表编码
        }
      };
      let paramD = that.$getParams(queryObj);
      // 调用中台API方法（可复用）
      requestAPI(paramD).then(response => {
        if (
          response.data[queryObj.apiConfig.ServiceCode].result == "1"
          //&&response.data[queryObj.apiConfig.ServiceCode].rows != ""
        ) {
          that.options = response.data[queryObj.apiConfig.ServiceCode].rows;
        }
      });
      that.value = that.code;
    },
    reset: function() {
      let that = this;
      this.value = "";
    },
    sendCode() {
      this.$emit("changeCode", this.value);
    }
  }
};
</script>

<style scoped>
</style>
